import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'


import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// https://vite.dev/config/
export default defineConfig({
  base: './',
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  publicPath: "",
  productionSourceMap: false,
  server: {
    port: "5173", // 请求地址的端口号，在本项目是38080
    proxy: {
      '/v1/api': {
        target: "http://127.0.0.1:6004", // 真实的服务器地址
        changeOrigin: true, //
        secure: false, // 默认情况下，不接受运行在 HTTPS 上，且使用了无效证书的后端服务器。如果你想要接受设为false
        ws: false, // 是否启用websockets
        // 是否重写
        pathRewrite: {
          "^/v1/api": "/v1/api",
        },
      },
      '/upload': {
        target: 'http://localhost:3300/upload',
        changeOrigin: true,
        ws: true,
        rewrite: (path) => path.replace(new RegExp(`^/upload`), ''),
      },
    },
    warmup: {
      clientFiles: ['./index.html', './src/{views,components}/*'],
    },
  },
})
